<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Weixin\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class CertController extends WeixinController {
    protected function _initialize(){
        require_once('ThinkPHP/Library/Vendor/api_payment/llpaypayment.php');
        require_once('ThinkPHP/Library/Vendor/OCR_API.php');


        /* 读取站点配置 */
        $config = api('Config/lists');
        C($config); //添加配置
        if(!C('WEB_SITE_CLOSE')){
            $this->error('站点已经关闭，请稍后访问~');
        }
        $options = array(
            'token'     => $this->token,   // 填写你设定的key
            'appid'     => $this->appid,    // 填写高级调用功能的appid
            'appsecret' => $this->appsecret // 填写高级调用功能的密钥
        );
        $this->weixin = new \Common\Extend\Wechat\Wechat($options);
        $weixin = cookie('WeixinLogin');
        if(empty($weixin)){
            $this->oauth();
        }else{
            $this->uid          = $weixin['uid'];
            $this->access_token = $weixin['access_token'];
            $this->openid       = $weixin['openid'];
        }
        $where['id'] =$this->uid;
        $count = D('ucenter_member')->where($where)->getField('mobile');
        if(empty($count)){
            $this->redirect('User/mobile');
        }
        
    }

	//系统首页
    public function index(){
      /*  $api = new \Common\Extend\Api\ApiClient();
        $data =  [];
        $a = $api->credit()->Send('post')->data($data);
        print_r($a);exit;

        exit;*/

        if(IS_POST){
            $username = I('post.username');
            $password = I('post.password');
            if(empty($username)){
                $this->error('学信账号不能为空');
            }elseif(empty($password)){
                $this->error('学信密码不能为空');
            }
            $api = new \Common\Extend\Api\ApiClient();
            $api = $api->credit();
            $api->method    = 'api.education.get';
            $api->username  = $username;
            $api->password  = base64_encode($password);
            $data=$api->Send('post','json')->data();
            if($data['code']=='0000'){
                session('APPToken',$data['token']);
                $this->success('学信网授权成功，下一步完成认证!');
            }else{
                $this->error('您的学信账号或密码不正确'.$data['code']);
            }
        }else{
            C('WEB_SITE_TITLE','学信认证');
            $this->display('cert');
        }
    }

    public function xuexininfo(){
        $Token =  session('APPToken');
        $model =  D('Chsi');
        $info = $model->UpdateXueXin(1,$Token);
        print_r($info);exit;
    }

}